home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Mosquito.lua < prev    next >
Text File  |  2010-08-31  |  6KB  |  181 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Mosquito + Projectile Mosquito
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, December 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.mosquito={}
  10. cc.mosquito.mosquito={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.mosquito.gfx_wpn0=loadgfx("weapons/mosquito0.bmp")                -- Weapon Image Frame 0
  14. setmidhandle(cc.mosquito.gfx_wpn0)
  15. cc.mosquito.gfx_wpn1=loadgfx("weapons/mosquito1.bmp")                -- Weapon Image Frame 1
  16. setmidhandle(cc.mosquito.gfx_wpn1)
  17. cc.mosquito.sfx_attack=loadsfx("mosquito.ogg")                        -- Attack Sound
  18.  
  19. --------------------------------------------------------------------------------
  20. -- Weapon: Mosquito
  21. --------------------------------------------------------------------------------
  22.  
  23. cc.mosquito.id=addweapon("cc.mosquito","Mosquito",cc.mosquito.gfx_wpn0,0,2)    -- Add Weapon (0 uses, first in round 2)
  24.  
  25. function cc.mosquito.draw()                                            -- Draw
  26.     -- Animation
  27.     weapon_timer=weapon_timer+1
  28.     if weapon_timer>4 then
  29.         weapon_timer=0
  30.         weapon_mode=1-weapon_mode
  31.     end
  32.     -- Draw
  33.     if weapon_shots==0 then
  34.         setblend(blend_alpha)
  35.         setalpha(1)
  36.         setcolor(255,255,255)
  37.         if weapon_mode==0 then
  38.             drawinhand(cc.mosquito.gfx_wpn0,6,0)
  39.         else
  40.             drawinhand(cc.mosquito.gfx_wpn1,6,0)
  41.         end
  42.         -- HUD Crosshair
  43.         hudcrosshair(6,3)
  44.     end
  45. end
  46.  
  47. function cc.mosquito.attack(attack)                                    -- Attack
  48.     if (weapon_shots<=0) then
  49.         -- Fire a projectile (on release/full charge)
  50.         if (attack==1) then
  51.             -- No more weapon switching!
  52.             useweapon(0)
  53.             -- Disable player control
  54.             playercontrol(0)
  55.             -- Make sure that there is enough round time
  56.             secondsleft=math.floor(getframesleft()/50)
  57.             changeturntime(30-secondsleft)
  58.             -- Launch
  59.             weapon_shots=weapon_shots+1
  60.             id=createprojectile(cc.mosquito.mosquito.id)
  61.             projectiles[id]={}
  62.             -- Ignore collision with current player at beginning
  63.             projectiles[id].ignore=playercurrent()
  64.             -- Set initial position of projectile
  65.             projectiles[id].x=getplayerx(0)+(6*getplayerdirection(0))+math.sin(math.rad(getplayerrotation(0)))*3.0
  66.             projectiles[id].y=getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*3.0
  67.             -- Set speed of projectile
  68.             projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*3.0
  69.             projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*3.0
  70.             -- Set timer
  71.             projectiles[id].timer=30*50
  72.             -- Effects
  73.             recoil(2)
  74.         end
  75.     end
  76. end
  77.  
  78. --------------------------------------------------------------------------------
  79. -- Projectile: Mosquito
  80. --------------------------------------------------------------------------------
  81.  
  82. cc.mosquito.mosquito.id=addprojectile("cc.mosquito.mosquito")        -- Add Projectile
  83.  
  84. function cc.mosquito.mosquito.draw(id)                                -- Draw
  85.     -- Setup draw mode
  86.     setblend(blend_alpha)
  87.     setalpha(1)
  88.     setcolor(255,255,255)
  89.     setscale(1,1)
  90.     -- Calculate projectile rotation
  91.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  92.     -- Draw projectile
  93.     if weapon_mode==0 then
  94.         drawimage(cc.mosquito.gfx_wpn0,projectiles[id].x,projectiles[id].y)
  95.     else
  96.         drawimage(cc.mosquito.gfx_wpn1,projectiles[id].x,projectiles[id].y)
  97.     end
  98.     -- Draw Arrow if out of Screen
  99.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  100.     -- Sound
  101.     if channelplaying(0)==0 then playsound(cc.mosquito.sfx_attack,0) end
  102. end
  103.  
  104. function cc.mosquito.mosquito.update(id)                            -- Update
  105.     -- Control by player
  106.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  107.     if keydown(key_left)==1 then
  108.         rot=rot-5
  109.     elseif keydown(key_right)==1 then
  110.         rot=rot+5
  111.     end
  112.     projectiles[id].sx=math.sin(math.rad(rot))*3.0
  113.     projectiles[id].sy=-math.cos(math.rad(rot))*3.0
  114.     -- Wind influence on speed
  115.     projectiles[id].sx=projectiles[id].sx+getwind()*0.5
  116.     -- Move (in substep loop for optimal collision precision)
  117.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  118.     msubx=projectiles[id].sx/msubt
  119.     msuby=projectiles[id].sy/msubt
  120.     for i=1,msubt,1 do
  121.         projectiles[id].x=projectiles[id].x+msubx
  122.         projectiles[id].y=projectiles[id].y+msuby
  123.         -- Collision
  124.         if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*3,projectiles[id].y-math.cos(math.rad(rot))*3)==1 then
  125.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  126.                 projectiles[id].timer=0
  127.                 if playercollision()>0 and playercollision()~=projectiles[id].ignore then
  128.                     -- Intoxicate
  129.                     playerstate(playercollision(),state_poisoned,1)
  130.                     -- Damage
  131.                     playerdamage(playercollision(),5)
  132.                 end
  133.                 break
  134.             end
  135.         else
  136.             projectiles[id].ignore=0
  137.         end
  138.         -- Water
  139.         if (projectiles[id].y)>getwatery()-30 then
  140.             -- Stop SFX Loop
  141.             stopchannel(0)
  142.             -- Effects
  143.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  144.             playsound(sfx_hitwater3)
  145.             -- Free projectile
  146.             freeprojectile(id)
  147.             -- End Turn
  148.             endturn()
  149.             break
  150.         end
  151.     end
  152.     -- Timer / Explode
  153.     projectiles[id].timer=projectiles[id].timer-1
  154.     if projectiles[id].timer<=0 then
  155.         -- Stop SFX Loop
  156.         stopchannel(0)
  157.         -- Splatter
  158.         playsound(sfx_splatter2)
  159.         -- Green Insect Stuff
  160.         if math.random(0,1)==1 then
  161.             terrainalphaimage(gfx_blood25,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,0,math.random(200,250),0)
  162.         else
  163.             terrainalphaimage(gfx_blood50,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,0,math.random(200,250),0)
  164.         end
  165.         particle(p_smoke,projectiles[id].x,projectiles[id].y)
  166.         particlealpha(1.0)
  167.         particlecolor(0,255,0)
  168.         particlesize(20,20)
  169.         particlefadealpha(0.009)
  170.         for i=1,5,1 do
  171.             particle(p_blood,projectiles[id].x,projectiles[id].y)
  172.             particlecolor(0,255,0)
  173.         end
  174.         -- Free projectile
  175.         freeprojectile(id)
  176.         -- End Turn
  177.         endturn()
  178.     end
  179.     -- Scroll to projectile
  180.     scroll(projectiles[id].x,projectiles[id].y)
  181. end